#!/usr/local/bin/python3
# *_* coding: UTF-8 *_*
# @IDE: PyCharm
# @Version: Python3.97
# @Author: Kendrick.Kc
# @Email: 509556985@qq.com
# @File: get_volatility.py
# @Inst: 采集高波动率交易对
# @Time: 2023/6/26 22:07
# -----


from binance_dgs.filter_all_symbol import FilterSymbol
from utils.timestamp import to_day_time_stamp, time_stamp_date


def get_db_volatility(binance):
    """ 从数据库获取高波动率交易对 """
    def vol_data():
        binance.logger_info(f"采集高波动率交易对......")
        vol = FilterSymbol(binance).get_rv(fil_symbol=binance.cache_get(binance.parameter.db_coll_trading_symbol))
        binance.cache_set(binance.parameter.db_coll_high_volatility, {
            "timeStamp": to_day_time_stamp(),
            "vol": vol
        })
        binance.logger_info(f"{binance.parameter.db_coll_high_volatility}数据采集完成.")
        return vol

    try:
        res_vol = binance.cache_get(binance.parameter.db_coll_high_volatility)
        if time_stamp_date(res_vol["timeStamp"]) == time_stamp_date() and res_vol["vol"] != []:
            return res_vol["vol"]
        else:
            return vol_data()
    except:
        return vol_data()
